package cn.edu.qfnu.oj.service.impl;

import cn.edu.qfnu.common.service.Impl.BaseServiceImpl;
import cn.edu.qfnu.oj.entity.Problem;
import cn.edu.qfnu.oj.entity.Task;
import cn.edu.qfnu.oj.service.TaskService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Set;


@Service("taskService")
public class TaskServiceImpl extends BaseServiceImpl<Task, Integer> implements TaskService{

    @Override
    public Task modify(Task task, String title, String content, String start, String duration,
                       String term, Set<Problem> problems) {
        if (!title.equals(task.getTitle())) {
            task.setTitle(title);
        }
        if (!content.equals(task.getContent())) {
            task.setContent(content);
        }
        if (!LocalDateTime.parse(start).isEqual(task.getStartTime())) {
            task.setStartTime(LocalDateTime.parse(start));
        }
        if (!LocalDateTime.parse(start).plusDays(Long.parseLong(duration)).isEqual(task.getEndTime())) {
            task.setEndTime(LocalDateTime.parse(start).plusDays(Long.parseLong(duration)));
        }
        if (!problems.equals(task.getProblems())) {
            task.setProblems(problems);
        }
        if (!term.equals(task.getTerm())) {
            task.setTerm(term);
        }

        return task;
    }
}
